package com.macaline.framemarker.dataBase.mysql.builder;

import com.macaline.framemarker.dataBase.framework.bean.Column;
import com.macaline.framemarker.dataBase.framework.bean.Table;
import com.macaline.framemarker.dataBase.framework.builder.AbstractTableBuilder;

import java.util.LinkedList;
import java.util.List;

/**
 * MySQL表构造器
 */
public class MySqlTableBuilder extends AbstractTableBuilder {


    private String tabName; // 表名
    private List<Column> columnList; // 字段列表
    private String comment; // 注释

    public static void main(String[] args) {

    }

    @Override
    public Table build() {
        Table table = new Table();
        table.setName(tabName);
        table.setColumns(columnList);
        table.setComment(comment);
        return table;
    }

    @Override
    public AbstractTableBuilder tabName(String tabName) {
        this.tabName = tabName;
        return this;
    }

    @Override
    public AbstractTableBuilder column(Column column) {
        if(this.columnList == null){
            this.columnList = new LinkedList<Column>();
        }
        this.columnList.add(column);
        return this;
    }

    @Override
    public void columns(List<Column> columnList) {
        this.columnList = columnList;
    }

    @Override
    public AbstractTableBuilder comment(String comment) {
        this.comment = comment;
        return this;
    }
}
